<?php
namespace app\api\controller;
use app\common\controller\Base;


/**
 * 红包模块  - 无需登录
 */
class RedPub extends Base{
    protected $tn = 'common/red_packet';

    //红包领取详情
    public function redInfo(){
        if(!isset($this->post['id']) || intval($this->post['id']) <= 0){
            $this->apiReturn(0,'参数id丢失');
        }

        $model = model($this->tn)->find(intval($this->post['id']));
        if(is_null($model)){
            $this->apiReturn(0,'红包不存在或已被删除');
        }
        //领取红包数量
        $model['g_num'] = $model['num'] - $model['get_num'];
        $model['g_price'] = ($model['price']*100 - $model['odd_price']*100)/100;
        $list =db('red_packet_get')->alias('g')->join(['bz_user' => 'u'],'u.id = g.get_user_id')->where('g.foreign_key',intval($this->post['id']))->field('photo_path,nick_name,FROM_UNIXTIME(g.add_time,"%H:%i") as get_time,price')->order('g.add_time desc')->select();

        $model['get_list'] = empty($list)?[]:$list;
        $this->apiReturn(1,'详情',$model);
    } 


}
